import request from './request';

/**
 * 获取部门列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getDepartments(params) {
  return request({
    url: '/departments',
    method: 'get',
    params
  });
}

/**
 * 创建部门
 * @param {Object} data - 部门信息
 * @param {string} data.name - 部门名称
 * @param {string} data.description - 部门描述
 * @param {number} data.parentId - 父部门ID
 * @returns {Promise}
 */
export function createDepartment(data) {
  return request({
    url: '/departments',
    method: 'post',
    data
  });
}

/**
 * 获取部门详情
 * @param {number} id - 部门ID
 * @returns {Promise}
 */
export function getDepartment(id) {
  return request({
    url: `/departments/${id}`,
    method: 'get'
  });
}

/**
 * 更新部门
 * @param {number} id - 部门ID
 * @param {Object} data - 部门信息
 * @returns {Promise}
 */
export function updateDepartment(id, data) {
  return request({
    url: `/departments/${id}`,
    method: 'put',
    data
  });
}

/**
 * 删除部门
 * @param {number} id - 部门ID
 * @returns {Promise}
 */
export function deleteDepartment(id) {
  return request({
    url: `/departments/${id}`,
    method: 'delete'
  });
}